package com.jxc.action.rkgl;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.jxc.action.BaseAction;
import com.jxc.model.vo.DataGrid;
import com.jxc.model.vo.Json;
import com.jxc.model.vo.SessionInfo;
import com.jxc.model.vo.VOrderReturnlist;
import com.jxc.service.OrderReturnServiceI;
import com.jxc.util.ExceptionUtil;
import com.jxc.util.ResourceUtil;
import com.opensymphony.xwork2.ModelDriven;

@Namespace("/rkgl")
@Action(value = "orderReturnAction", results = {
		@Result(name = "orderReturn", location = "/order/orderReturn.jsp"),
		@Result(name = "orderReturnAdd", location = "/order/orderReturnAdd.jsp"),
		@Result(name = "orderReturnInfo", location = "/order/orderReturnInfo.jsp") })
public class OrderReturnAction extends BaseAction implements
		ModelDriven<VOrderReturnlist> {
	private final static Logger logger = Logger
			.getLogger(OrderReturnAction.class);
	@Autowired
	private OrderReturnServiceI orderReturnService;

	private VOrderReturnlist model = new VOrderReturnlist();
	
	private String items;

	@Override
	public VOrderReturnlist getModel() {
		return model;
	}

	public String getItems() {
		return items;
	}

	public void setItems(String items) {
		this.items = items;
	}

	public String orderReturn() {
		getSubAuths("RKGL_RKTH");
		return "orderReturn";
	}

	public void noAuth_datagrid() {
		DataGrid subDg = orderReturnService.datagrid(model);
		this.writeJson(subDg);
	}

	public String orderReturnAdd() {
		return "orderReturnAdd";
	}

	public void add() {
		Json j = new Json();
		try {
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext
					.getRequest().getSession().getAttribute(
							ResourceUtil.getSessionInfoName());
			model.setUid(sessionInfo.getUserId());
			orderReturnService.save(model,items);
			j.setMsg("添加成功！");
			j.setSuccess(true);
		} catch (Exception e) {
			j.setMsg("添加失败！");
			logger.info(ExceptionUtil.getExceptionMessage(e));
		}
		super.writeJson(j);
	}

	public void delete() {
		Json j = new Json();
		orderReturnService.delete(model.getIds());
		j.setSuccess(true);
		j.setMsg("删除成功!");
		super.writeJson(j);
	}
	public String orderReturnInfo(){
		getRequest().setAttribute("id", model.getId());
		return "orderReturnInfo";
	}
	
	public void noAuth_checkOrderReturn(){
		writeJson(orderReturnService.search(model));
	}
	
	public void noAuth_checkItems(){
		writeJson(orderReturnService.getItems(model));
	}
}
